package com.doyens.mapper;

import com.doyens.pojo.DTO;
import com.doyens.pojo.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface StudentMapper {

    @Results({
            @Result(column = "sid",property = "sid"),
            @Result(column = "sname",property = "sname"),
            @Result(column = "birthday",property = "birthday"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "photo",property = "photo"),
            @Result(column = "sid",property = "schedules",javaType = List.class,
                    many = @Many(select = "com.doyens.mapper.ScheduleMapper.findById"))
    })
    @Select("select * from student order by sid")
    List<Student> findAll();

    @Delete("delete from stu_schedule where sid=#{id}")
    void delById(Integer id);

    @Delete("delete from student where sid=#{id}")
    int del(Integer id);

    @Insert("insert into student (sname,birthday,sex,photo) values (#{sname},#{birthday},#{sex},#{photo})")
    @Options(useGeneratedKeys=true, keyProperty="sid", keyColumn="id")
    void save(Student student);

    @Insert("insert into stu_schedule (id,schedule) values (#{sid},#{scheduleId})")
    void saveSd(@Param("sid") Integer sid, @Param("scheduleId") Integer scheduleId);

    void findByCondition(DTO dto);
}
